package com.tengju.user.domain.model.doc;

import com.tengju.user.domain.annotation.ElasticCryptEntity;
import com.tengju.user.domain.annotation.ElasticDecrypt;
import com.tengju.user.domain.annotation.ElasticEncrypt;
import com.tengju.user.domain.annotation.Sensitive;
import com.tengju.user.domain.model.user.StarLevelEnum;
import com.tengju.user.domain.shared.SensitiveFieldType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.List;

/**
 * @Author: 李大仙
 * @Date: 2021/3/19 2:07 下午
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Document(indexName = "user_doc", refreshInterval = "-1")
@ElasticCryptEntity(cryptFields = {"name","mobile"})
public class UserDocument {


    public static final String ID_CODE = "idCode";
    public static final String TJ_USER_ID = "tjUserId";
    public static final String ABM_USER_ID = "abmUserId";
    public static final String MOBILE = "mobile";
    public static final String NAME = "name";
    public static final String PARENT_ID_CODE = "parentIdCode";
    public static final String STAR_LEVEL = "starLevel";
    public static final String BRAND_PROVIDER_LEVEL = "brandProviderLevel";
    public static final String STAR_SIGN_STATUS = "starSignStatus";
    public static final String SIGN_TARGET_STAR_LEVEL = "signTargetStarLevel";
    public static final String TARGET_STAR_LEVEL = "targetStarLevel";
    public static final String STAR_ADD_DATE = "starAddDate";
    public static final String BLACK_ADD_DATE = "blackAddDate";
    public static final String CLUB_ID = "clubId";
    public static final String CLUB_NAME = "clubName";
    public static final String NICKNAME = "nickName";
    public static final String REGISTER_TIME = "registerTime";
    public static final String STAR_RISE_TIME = "starRiseTime";
    public static final String OWNER_EC_ID_CODE = "ownerEcIdCode";
    public static final String OWNER_SEC_ID_CODE = "ownerSecIdCode";
    public static final String OWNER_EEC_ID_CODE = "ownerEecIdCode";
    public static final String OWNER_GEN_SEC_ID_CODE = "ownerGenSecIdCode";
    public static final String OWNER_CITY_ID_CODE = "ownerCityIdCode";
    public static final String OWNER_GEN_OPERATOR_ID_CODE = "ownerGenOperatorIdCode";
    public static final String SENTIMENT_OPERATOR = "sentiments.operator.keyword";
    public static final String SENTIMENT_CONTEXT = "sentiments.context";
    public static final String ABM_HEAD_IMAGE = "abmHeadImage";
    public static final String TENGJU_HEAD_IMAGE = "tengjuHeadImage";
    public static final String DOMINATION_NOTE_LEADER = "dominationNotes.leaderId";
    public static final String DOMINATION_NOTE_REMARK = "dominationNotes.remark";
    public static final String LAST_DEMOTION_OPERATING = "lastDemotionOperating";
    public static final String LAST_DEMOTION_TIME = "lastDemotionTime";


    /**
     * idCode作为主键，idCode为空的数据不保存
     */
    @Id
    private Long idCode;
    /**
     * tengju 的user_info表user_id
     */
    @Field(type = FieldType.Long)
    private Long tjUserId;
    /**
     * ABM 的w_user表的id
     */
    @Field(type = FieldType.Long)
    private Long abmUserId;
    /**
     * ABM手机号
     */
    @Sensitive(type = SensitiveFieldType.MOBILE)
    @Field(type = FieldType.Keyword)
    private String mobile;
    /**
     * 上级编号
     */
    @Field(type = FieldType.Long)
    private Long parentIdCode;
    /**
     * 星级等级
     */
    @Field(type = FieldType.Integer)
    private Integer starLevel;
    /**
     * 代理等级
     */
    @Field(type = FieldType.Integer)
    private Integer brandProviderLevel;
    /**
     * 签约状态
     */
    @Field(type = FieldType.Integer)
    private Integer starSignStatus;
    /**
     * 签约目标星级等级
     */
    @Field(type = FieldType.Integer)
    private Integer signTargetStarLevel;
    /**
     * 即将晋升等级
     */
    @Field(type = FieldType.Integer)
    private Integer targetStarLevel;
    /**
     * 最近一次星级晋升日期
     */
    @Field(type = FieldType.Long)
    private Long starAddDate;
    /**
     * 最近一次升级黑卡时间
     */
    @Field(type = FieldType.Long)
    private Long blackAddDate;
    /**
     * 俱乐部id
     */
    @Field(type = FieldType.Long)
    private Long clubId;
    /**
     * 俱乐部名称
     */
    @Field(type = FieldType.Keyword)
    private String clubName;
    /**
     * 昵称
     */
    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    private String nickName;
    /**
     * 注册时间
     */
    @Field(type = FieldType.Long)
    private Long registerTime;
    /**
     * 星级升级时间（每次变更时间）
     */
    @Field(type = FieldType.Long)
    private Long starRiseTime;
    /**
     * 所属ec
     */
    @Field(type = FieldType.Long)
    private Long ownerEcIdCode;
    /**
     * 所属sec
     */
    @Field(type = FieldType.Long)
    private Long ownerSecIdCode;
    /**
     * 所属eec
     */
    @Field(type = FieldType.Long)
    private Long ownerEecIdCode;
    /**
     * 广义所属sec/sec
     */
    @Field(type = FieldType.Long)
    private Long ownerGenSecIdCode;
    /**
     * 广义运营商
     */
    @Field(type = FieldType.Long)
    private Long ownerGenOperatorIdCode;
    /**
     * 所属城市服务商
     */
    @Field(type = FieldType.Long)
    private Long ownerCityIdCode;
    /**
     * ABM姓名
     */
    @Field(type = FieldType.Keyword)
    @Sensitive(type = SensitiveFieldType.NAME)
    private String name;
    /**
     * 经销商头像
     */
    @Field(type = FieldType.Keyword)
    private String abmHeadImage;
    /**
     * 服务商头像
     */
    @Field(type = FieldType.Keyword)
    private String tengjuHeadImage;
    /**
     * 管辖上级给自己的备注
     */
    @Field(type = FieldType.Object)
    private List<DominationNoteDocument> dominationNotes;
    /**
     * 升降级操作 1：升级 2：降级
     */
    @Field(type = FieldType.Integer)
    private Integer lastDemotionOperating;
    /**
     * 升降级时间
     */
    @Field(type = FieldType.Long)
    private Long lastDemotionTime;

    public String getHeadImage() {
        if (StarLevelEnum.NONE == StarLevelEnum.parseByCode(this.starLevel)) {
            return abmHeadImage;
        } else {
            return tengjuHeadImage;
        }
    }

    /**
     * 客情信息
     */
    @Field(type = FieldType.Object)
    private List<SentimentDocument> sentiments;
}